#
# @lc app=leetcode.cn id=1 lang=python
#
# [1] 两数之和
#

# @lc code=start
class Solution(object):
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """

        # # 暴力法
        # for i in nums:
        #     if (target-i in nums):
        #         if i == target-i:
        #             if nums.count(i) == 1:
        #                 continue
        #             else:
        #                 return [nums.index(i), nums.index(target-i, nums.index(i)+1)]
        #         else:
        #             return [nums.index(i), nums.index(target-i)]
        
        # 暴力法
        lens = len(nums)
        j=-1
        for i in range(1,lens):
            temp = nums[:i]
            if (target - nums[i]) in temp:
                j = temp.index(target - nums[i])
                break
        if j>=0:
            return [j,i]
        
        #哈希表
        hashmap={}
        for ind,num in enumerate(nums):
            hashmap[num] = ind
        for i,num in enumerate(nums):
            j = hashmap.get(target - num)
            if j is not None and i!=j:
                return [i,j]
            
        #哈希表
        hashmap={}
        for i,num in enumerate(nums):
            if hashmap.get(target - num) is not None:
                return [i,hashmap.get(target - num)]
            hashmap[num] = i #这句不能放在if语句之前，解决list中有重复值或target-num=num的情况

# @lc code=end
